dp math number theory *1500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define endl '\n'
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N = 1e6+5;
int arr[N];

int mod = 1000000007 ;

vector < int > vec ;
set < int > st ;
map < int, int > mp;


int32_t main()
{
    fast

    int T = 1 ;
    // cin >> T ;
    while(T--)
    {
       int n ; cin >> n ;

       for(int i=1 ; i <= n ; i++)
       {
           int x ;
           cin >> x ;
           arr[x] = 1 ;
       }

       int ans = 0 ;

       for(int i=1 ; i <= 1e6 ; i++)
       {
           for(int j= i + i ; j <= 1e6 ; j += i)
            if(arr[j]) arr[j] = max(arr[j] , arr[i] + 1) ;

           ans = max(ans , arr[i]);
       }

       cout << ans ;

    }
}


Comments

Submit
0 Comments
More Questions

1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training
455A - Boredom
1099A - Snowball